package Demo1;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        //需求：调用User对象的sayHello方法
        //1.传统方法：new对象，调方法
        User u1 = new User();
        u1.sayHello();
        //2.使用反射机制
        Class cls = Class.forName("Demo1.User");
        User u2 = (User)cls.newInstance();
        u2.sayHello();
        //3.使用Spring容器来管理对象
        AnnotationConfigApplicationContext context
                =new AnnotationConfigApplicationContext("demo1");
        User u3 = context.getBean(User.class);
        u3.sayHello();
    }
}
